package me.firstapp.repository.system.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import me.firstapp.module.system.Statistics;
import me.firstapp.repository.base.impl.EntityRepositoryImpl;
import me.firstapp.repository.system.StatisticsRepository;

@Repository
public class StatisticsRepositoryImpl extends EntityRepositoryImpl<Statistics> implements StatisticsRepository {

	@Override
	protected Class<Statistics> getPersistentClass() {
		return Statistics.class;
	}

	@Override
	public Statistics findStatisticsByClientId(Long apiClientId) {
		StringBuilder sql = new StringBuilder(" FROM Statistics bean WHERE 1=1 ");
		Map<String, Object> parameters = new HashMap<>();

		sql.append(" AND bean.apiClientId =:apiClientId ");
		parameters.put("apiClientId", apiClientId);

		List<Statistics> result = super.query(Statistics.class, sql.toString(), parameters);
		return result.isEmpty() ? null : result.get(0);
	}

}
